<script language = 'javascript' type='text/javascript'>

function mostrarAba(id) {

		abaVisivel = document.getElementById('NoticiasAbaVisivel').value;
		document.getElementById('aba'+abaVisivel).style.display = 'none';

		document.getElementById('NoticiasAbaVisivel').value = id;
		document.getElementById('aba'+id).style.display = '';

		/* Modifica a cor da aba */
		document.getElementById('atab'+abaVisivel).className = 'tabBegin';
		document.getElementById('litab'+abaVisivel).className = 'tabEnd';

		document.getElementById('atab'+id).className = 'tabBeginSelected';
		document.getElementById('litab'+id).className = 'tabEndSelected';
	}
</script>

<?php
	echo "<input type='hidden' id='NoticiasAbaVisivel' value='0'>";

	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');

	echo '<div> Cadastre e visualize aqui as notícias relacionadas a sua entidade. <br><br> </div>';

	$addButton = "<span class=\"buttonAdd\">Cadastrar notícia</span>";
	echo html_entity_decode($html->link($addButton, '/noticias/add/',array('class'=>'button')));

	/* Exibindo abas  */

	echo "<div id='tab' class='tab'>";
	echo "<ul>";

		echo "<li id='litab0' class='tabEndSelected' style='padding-bottom: 6px;'>";
		echo "<a id='atab0' class='tabBeginSelected' href='javascript:mostrarAba(0);'>".
				"<span id='spantab0' > Todas as notícias</span></a>\n";
		echo "</li>";

		echo "<li id='litab1' class='tabEnd' style='padding-bottom: 6px;'>";
		echo "<a id='atab1' class='tabBegin' href='javascript:mostrarAba(1); '>".
			"<span  id='spantab1'>Minhas notícias</span></a>";
		echo "</li>";

		echo "<li id='litab2' class='tabEnd' style='padding-bottom: 6px;'>";
		echo "<a id='atab2' class='tabBegin' href='javascript:mostrarAba(2); '>".
			"<span  id='spantab2'>Rascunhos</span></a>";
		echo "</li>";

	echo "</ul>";
	echo "</div>";

	/* Noticias gerais */

	echo "<div class='dashed' id='aba0' style='display:block;'>";

	if (isset($noticias_geral) && is_array($noticias_geral) && (!empty($noticias_geral))) {
		echo "<table>";
		echo "<tr class='sort'>";
		echo "<thead>";
		echo "<tr class='tableHeader'>";
		echo "<div></div>";
		echo "<th class='tableHeaderBegin'> Título </th>".
			"<th class='tableHeaderMiddle'> Publicada em </th>".
			"<th class='tableHeaderMiddle'> Autor </th>".
			"<th class='tableHeaderEnd' colspan = 2> Opções </th>";

		echo "</tr>";
		echo "</thead>";

		$i=0;
		foreach ($noticias_geral as $noticia) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($noticia['Noticia']['title'],'/noticias/view/'.$noticia['Noticia']['id'])."</td>";

			echo "<td><small>".date("d/m/Y",strtotime($noticia['Noticia']['publishedon']))."</small></td>";

			echo "<td>".$html->link($noticia['User']['name'],'/users/view/'.$noticia['User']['id'])."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/noticias/edit/'.$noticia['Noticia']['id']))."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/noticias/delete/'.$noticia['Noticia']['id'], array(), 'Confirma a exclusÃ£o deste item?'))."</td>";
			echo "</tr>";
		}
		echo "</table>";
	} else {
		echo "<p>Não há nenhuma notícia publicada.</p><br>";
	}

	echo "</div>";

	echo "<div class='dashed' id='aba1' style='display:none;'>";

		if (isset($noticias_publicadas) && is_array($noticias_publicadas) && (!empty($noticias_publicadas))) {
		echo "<table>";
		echo "<tr class='sort'>";
		echo "<thead>";
		echo "<tr class='tableHeader'>";
		echo "<div></div>";
		echo "<th class='tableHeaderBegin'> Título </th>".
			"<th class='tableHeaderMiddle'> Pública </th>".
			"<th class='tableHeaderMiddle'> Publicada em </th>".
			"<th class='tableHeaderMiddle'> Autor </th>".
			"<th class='tableHeaderEnd' colspan = 2> Opções </th>";

		echo "</tr>";
		echo "</thead>";
		$i=0;
		foreach ($noticias_publicadas as $noticia) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td><small>".$noticia['Noticia']['title']."</small></td>";


			echo "<td><small>";

			if ($noticia['Noticia']['public'] == 0) {
				echo "Não";
			} else {
				echo "Sim";
			}
			echo "</small></td>";

			echo "<td><small>".date("d/m/Y",strtotime($noticia['Noticia']['publishedon']))."</small></td>";

echo "<td>".$html->link($noticia['User']['name'],'/users/view/'.$noticia['User']['id'])."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/noticias/edit/'.$noticia['Noticia']['id']))."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/noticias/delete/'.$noticia['Noticia']['id'], array(), 'Confirma a exclusÃ£o deste item?'))."</td>";
			echo "</tr>";
		}
		echo "</table>";
	} else {
		echo "<p>Não há nenhuma notícia publicada por você.</p><br/>";
	}

	echo "</div>";


	echo "<div class='dashed' id='aba2' style='display:none;'>";
	if (isset($rascunhos) && is_array($rascunhos) && (!empty($rascunhos))) {
		echo "<table>";
		echo "<tr class='sort'>";
		echo "<thead>";

		echo "<tr class='tableHeader'>";
		echo "<div></div>";
			echo "<th class='tableHeaderBegin'> Título </th>".
			     "<th class='tableHeaderMiddle'> Autor </th>".
			     "<th class='tableHeaderEnd' colspan = 2> Opções </th>";
		echo "</tr>";
		echo "</thead>";

		$i=0;
		foreach ($rascunhos as $noticia) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td><small>".$noticia['Noticia']['title']."</small></td>";

			echo "<td>".$html->link($noticia['User']['name'],'/users/view/'.$noticia['User']['id'])."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/noticias/edit/'.$noticia['Noticia']['id']))."</td>";
			echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/noticias/delete/'.$noticia['Noticia']['id'], array(), 'Confirma a exclusÃ£o deste item?'))."</td>";
			echo "</tr>";
		}
		echo "</table>";
	} else {
		echo "<p>Não há rascunho de notícia.</p><br/>";
	}
	echo '</div>';
